<template>
  <div class="container clearfix">
    <!-- 搜索 -->
    <div class="search-bar">
      <div class="search-box">
        <div class="inp-box">
          <input type="text"
                 class="inp"
                 disabled
                 @click="toSeachPage"
                 placeholder="请输入搜索内容">
          <img mode="widthFix"
               src="https://h5.ameimeika.com/mp_images/shouye/search@2x.png"
               alt
               class="image">
        </div>
      </div>
    </div>
    <!-- tab列表 -->
    <scroll-view v-if="navData[0]"
                 scroll-x="true"
                 class="nav"
                 :scroll-left="navScrollLeft"
                 :scroll-with-animation="isAnimation">
      <block v-for="(item,index) in navData"
             :key="index">
        <div class="nav-item"
             :data-current="index"
             @click="switchNav($event,item.id)"
             :class="[currentTab == index ?'active':'']">{{item.name}}</div>
      </block>
    </scroll-view>
    <div class="content"
         :class="[{'isiphoneX':isIphoneX},{'notab':navData.length ==0}]">
      <div class="result">
        <scroll-view :scroll-y="true"
                     :style="{'height': '100%'}">
          <!-- 三级分类 -->
          <ul class="three_level"
              v-if="cates[0]">
            <li class="level"
                v-for="(item,i) in cates"
                :key="i"
                @click="three_detail(item)">{{item.name}}</li>
          </ul>
          <!-- 页面内容 -->
          <div class="page_con"
               v-if="projectData[0]">
            <!-- 名医推荐 -->
            <div class="title"
                 v-if="doctors[0]">名医推荐</div>
            <scroll-view scroll-x="true"
                         class="doctor"
                         scroll-with-animation="true"
                         v-if="doctors[0]">
              <block v-for="(item,i) in doctors"
                     :key="i">
                <div class="doc"
                     @click="doctor_detail(item)">
                  <div class="picbox">
                    <div class="doc_pic">
                      <img :src="img_url+item.image"
                           class="docimg"
                           mode="widthFix"
                           style="height:54px;">
                    </div>
                    <img v-if="item.is_v&&item.is_v == 1"
                         src="https://h5.ameimeika.com/mp_images/mp_2.4/search/vvvvv@2x.png"
                         class="doc_v">
                  </div>
                  <div class="doc_desc">
                    <p class="docname">{{item.name}}</p>
                    <p class="doczw">{{item.post}}</p>
                    <p class="dochos">{{item.hospitals_name}}</p>
                  </div>
                </div>
              </block>
            </scroll-view>
            <!-- 好院精选 -->
            <div class="title"
                 v-if="hospitals[0]">好院精选</div>
            <scroll-view scroll-x="true"
                         class="hospital"
                         scroll-with-animation="true"
                         v-if="hospitals[0]">
              <block v-for="(item,i) in hospitals"
                     :key="i">
                <div class="hos"
                     @click="hospital_detail(item)">
                  <div class="hosleval"
                       v-if="item.tags_name">
                    <div class="hosmsg">{{item.tags_name}}</div>
                  </div>
                  <div class="hospic">
                    <img class="hosimg"
                         :src="img_url+item.logo"
                         alt>
                  </div>
                  <div class="hosname">{{item.name}}</div>
                  <div class="hosaddress">
                    <img class="dwimg"
                         :src="base_url+'/mp_2.4/search/dingwei.png'"
                         v-if="base_url"
                         alt>
                    <div class="dzmsg">{{item.address}}</div>
                  </div>
                  <div class="hosscore">
                    <div class="lf">
                      <img class="star"
                           src="https://h5.ameimeika.com/mp_images/star/pingxing-liang@2x.png"
                           alt>
                      <span class="score">{{item.star}}分</span>
                    </div>
                    <div class="rt">项目&nbsp;{{item.beauty_project_count}}</div>
                  </div>
                </div>
              </block>
            </scroll-view>
            <!-- 热门项目 -->
            <div class="title"
                 v-if="projectData[0]">热门项目</div>
            <!-- 项目列表 -->
            <mallList :mallList="projectData"></mallList>
            <div class="daodi">因为甄选，所以珍稀</div>
          </div>
          <!-- 没有找到想要的内容 -->
          <div class="empty"
               v-if="empty">
            <img src="https://h5.ameimeika.com/mp_images/mp_2.7/empty@2x.png"
                 alt
                 class="nothing">
            <div class="text">没有找到宝宝想看的内容</div>
          </div>
        </scroll-view>
      </div>
    </div>
  </div>
</template>
<script>
import imageurl from "@/assets/js/image.js";
import common from "@/assets/js/mmk_common.js";
import mallList from "@/components/mall_List/mall_List_java";
export default {
  data () {
    return {
      base_url: common.image_resource,
      img_url: common.image_response,
      navData: [], //tab列表
      currentTab: 0, //当前点击tab
      navScrollLeft: 0, //nav移动位置
      windowWidth: 0,
      isAnimation: true, //是否有动画 -> 解决二级分类跳转滚动不到的问题
      isIphoneX: false,
      empty: false, //没有内容
      cates: [], //二级分类下的三级分类数据
      doctors: [], //医生数据
      hospitals: [], //医院数据
      projectData: [], //当前分类下项目数据
      type: "", //type 分类
      parent_id: "", //一级分类id
      cate_id: "", //二级分类id 110
      province_id: "", //省份id
      lat: 0, //纬度
      lng: 0 //经度
    };
  },
  components: {
    mallList
  },
  onLoad (options) {
    let that = this;
    Object.assign(this.$data, this.$options.data());
    let obj = JSON.parse(options.obj);
    this.type = obj.project_cate_type;
    switch (obj.project_cate_type) {
      case 1:
        this.parent_id = obj.id;
        break;
      case 2:
        this.parent_id = obj.parent_id;
        this.cate_id = obj.id;
    }
    that.getLocation();
    //一级分类名字
    wx.setNavigationBarTitle({
      title: obj.name
    });
    //获取系统信息
    wx.getSystemInfo({
      success: res => {
        this.windowWidth = res.windowWidth;
        if (res.model.search("iPhone X") != -1) {
          that.isIphoneX = true;
        }
      }
    });
    //获取tab数据
    this.getTabData();
    //获取省份id和经纬度
    wx.getStorage({
      key: "province_info",
      success: res => {
        let info = JSON.parse(res.data);
        that.province_id = info.province_id;
      },
      fail: () => {
      }
    });
  },
  onShow () { },
  methods: {
    //获取定位
    getLocation () {
      let that = this;
      wx.getLocation({
        type: "gcj02",
        success (res) {
          that.lng = res.longitude; // 经度
          that.lat = res.latitude; // 纬度
          that.getTwoResult(); //二级分类搜索
        },
        fail () {
          wx.showToast({
            title: "无法获取地理位置",
            icon: "none",
            duration: 2000,
            mask: true
          });
        }
      });
    },
    //搜索框
    toSeachPage () {
      wx.navigateTo({ url: "/pages/package_main/search_index/main?status=2" });
    },
    //tab切换
    switchNav (e, cate_id) {
      this.isAnimation = true;
      let cur = e.mp.currentTarget.dataset.current;
      //每个tab选项宽度占1/5
      let singleNavWidth = this.windowWidth / 5;
      //tab选项居中
      this.navScrollLeft = (cur - 2) * singleNavWidth;
      if (this.currentTab == cur) {
        return false;
      } else {
        this.currentTab = cur;
      }
      this.cate_id = cate_id;
      this.getTwoResult();
    },
    //三级分类详情
    three_detail (item) {
      wx.navigateTo({
        url: `/pages/package_projects/three_level/main?cate_name=${item.name}&cate_id=${
          item.id
          }`
      });
    },
    //医生详情
    doctor_detail (item) {
      wx.navigateTo({
        url: "/pages/package_projects/doctordetail/main?id=" + item.id
      });
    },
    //医院详情
    hospital_detail (item) {
      wx.navigateTo({ url: "/pages/package_projects/hospital_detail/main?hos_id=" + item.id });
    },
    //获取tab栏数据
    getTabData () {
      wx.showLoading({
        title: '', //提示的内容,
        mask: true, //显示透明蒙层，防止触摸穿透,
        success: res => { }
      });
      common.fly_post(
        "/api/com.mmk.reservation.api.OpenBeautyCategoriesProvider/1.0.0/twoCate.html",
        { id: this.parent_id },
        msg => {
          wx.hideLoading();
          let res = msg.data;
          if (res.code == 0) {
            this.navData = [...res.data];
            if (this.navData[0]) {
              if (this.type == 1) {
                //一级分类
                this.cate_id = this.navData[0].id;
              } else if (this.type == 2) {
                //二级分类
                this.cate_id = this.cate_id;
                this.isAnimation = false;
                let that = this;
                this.navData.filter(function (val, index, arr) {
                  if (val.id == that.cate_id) {
                    that.currentTab = index;
                    that.navScrollLeft = (index - 2) * (that.windowWidth / 5);
                  }
                });
              }
              this.getTwoResult(); //二级分类搜索
            } else {
              this.cates = [];
              this.doctors = [];
              this.hospitals = [];
              this.projectData = [];
              this.empty = true;
            }
          } else {
            wx.showToast({
              title: res.msg, //提示的内容,
              icon: 'none', //图标,
              duration: 1500, //延迟时间,
              mask: false, //显示透明蒙层，防止触摸穿透,
              success: res => { }
            });
          }
        }, "isJava"
      );
    },
    //二级分类搜索
    getTwoResult () {
      common.mmk_Loading(0);
      common.fly_post(
        '/api/com.mmk.reservation.api.OpenProjectProvider/1.0.0/projectTwoCateList.html',
        {
          cateId: this.cate_id + '', //二级分类id
          provinceId: this.province_id + '', //省份id
          lat: this.lat + '', //纬度
          lng: this.lng + '' //经度

        },
        result => {
          let res = result.data;
          common.mmk_Loading(1);
          if (res.code == 0) {
            this.cates = [...res.data.cates || []];
            this.doctors = [...res.data.doctors || []];
            this.hospitals = [...res.data.hospitals || []];
            this.projectData = [...res.data.projectData || []];
            if (
              (this.cates.length == 0 && this.projectData.length == 0) ||
              this.projectData.length == 0
            ) {
              this.empty = true;
            } else {
              this.empty = false;
            }
          } else {
            common.mmk_Loading(2, res.message);
          }
        }
        , 'isjava');
    }
  }
};
</script>

<style lang="less" scoped>
.container {
  width: 100%;
  height: 100%;
  box-sizing: border-box;
  background-color: #fff;
  display: flex;
  flex-direction: column;
  position: relative;
  // 搜索
  .search-bar {
    position: fixed;
    top: 0;
    left: 0;
    z-index: 9999;
    width: 100%;
    height: 38px;
    background-color: #fff;
    box-shadow: 0px 4px 8px 0px rgba(0, 0, 0, 0.06);
    .search-box {
      width: 324px;
      height: 38px;
      margin: 0 auto;
      position: relative;
      .inp-box {
        width: 304px;
        height: 32px;
        margin: 0 auto;
        position: relative;
        .inp {
          display: block;
          height: 100%;
          line-height: 32px;
          background: rgba(238, 238, 238, 1);
          border-radius: 16px;
          font-size: 14px;
          font-weight: 400;
          padding-left: 40px;
        }
        .image {
          width: 20px;
          position: absolute;
          left: 15px;
          top: 50%;
          transform: translateY(-50%);
        }
      }
    }
  }
  .nav {
    height: 40px;
    width: 100%;
    padding: 0 15px;
    box-sizing: border-box;
    overflow: hidden;
    line-height: 80rpx;
    background: #ffffff;
    font-size: 14px;
    font-family: PingFangSC-Regular;
    font-weight: 400;
    white-space: nowrap;
    position: fixed;
    top: 45px;
    left: 0;
    z-index: 9999;
    box-shadow: 0px 4px 8px 0px rgba(0, 0, 0, 0.06);
    .nav-item {
      margin-right: 20px;
      display: inline-block;
      text-align: center;
      &.active {
        position: relative;
        color: #f64665;
        &::before {
          content: "";
          width: 100%;
          height: 2px;
          background: rgba(255, 56, 62, 1);
          border-radius: 1px;
          position: absolute;
          bottom: 0;
          left: 0;
        }
      }
    }
  }
  .content {
    width: 100%;
    height: 86%;
    background-color: rgba(243, 244, 246, 1);
    position: absolute;
    top: 14%;
    left: 0;
    &.isiphoneX {
      top: 12%;
      height: 88%;
    }
    &.notab {
      top: 6%;
      height: 94%;
    }
    .result {
      position: relative;
      flex: 1;
      box-sizing: border-box;
      overflow: hidden;
      height: 100%;
      // 三级分类
      .three_level {
        background-color: #ffffff;
        padding: 15px 10px;
        box-sizing: border-box;
        display: flex;
        flex-wrap: wrap;
        .level {
          width: 108.8px;
          height: 32px;
          line-height: 32px;
          margin: 5px 5px;
          padding: 0 19px;
          box-sizing: border-box;
          background: rgba(246, 70, 101, 0.06);
          border-radius: 4px;
          text-align: center;
          font-family: PingFangSC-Regular;
          font-weight: 400;
          color: #666666;
          font-size: 12px;
          white-space: nowrap;
          overflow: hidden;
          text-overflow: ellipsis;
        }
      }
      // 页面内容
      .page_con {
        background-color: #ffffff;
        width: 100%;
        // 标题
        .title {
          padding: 0 15px;
          font-size: 16px;
          font-family: PingFangSC-Medium;
          font-weight: 500;
          color: #333333;
          line-height: 22px;
        }
        // 名医推荐
        .doctor {
          height: 105px;
          width: 100%;
          padding: 0 7px;
          margin: 8px 0;
          box-sizing: border-box;
          overflow: hidden;
          white-space: nowrap;
          .doc {
            width: 188px;
            height: 88px;
            line-height: 88px;
            background: rgba(255, 255, 255, 1);
            box-shadow: 0px 2px 7px rgba(224, 224, 224, 0.65);
            border-radius: 4px;
            margin-left: 8px;
            margin-top: 6px;
            padding: 15px 10px;
            box-sizing: border-box;
            display: inline-block;
            .picbox {
              display: inline-block;
              width: 54px;
              height: 54px;
              position: relative;
              .doc_pic {
                width: 54px;
                height: 54px;
                border-radius: 50%;
                overflow: hidden;
                .docimg {
                  width: 100%;
                }
              }
              .doc_v {
                display: inline-block;
                width: 18px;
                height: 18px;
                border-radius: 50%;
                position: absolute;
                right: 0;
                bottom: 0;
              }
            }

            .doc_desc {
              display: inline-block;
              width: 100px;
              font-family: PingFangSC-Medium;
              margin-left: 8px;
              .docname {
                font-size: 14px;
                font-weight: 500;
                color: #333333;
                line-height: 20px;
              }
              .doczw {
                font-size: 10px;
                font-weight: 400;
                color: #333333;
                line-height: 14px;
                margin: 4px 0;
              }
              .dochos {
                font-size: 10px;
                font-weight: 300;
                color: #999999;
                line-height: 14px;
                white-space: nowrap;
                overflow: hidden;
                text-overflow: ellipsis;
              }
            }
          }
        }
        //好院精选
        .hospital {
          height: 174px;
          width: 100%;
          padding: 0 5px;
          margin: 12px 0;
          box-sizing: border-box;
          overflow: hidden;
          white-space: nowrap;
          .hos {
            display: inline-block;
            width: 132px;
            height: 167px;
            background: rgba(255, 255, 255, 1);
            box-shadow: 0 3px 10px rgba(224, 224, 224, 0.65);
            border-radius: 4px;
            padding: 18px 8px;
            margin-left: 10px;
            box-sizing: border-box;
            position: relative;
            .hosleval {
              position: absolute;
              top: 3px;
              left: 9px;
              .hosmsg {
                padding-left: 12px;
                padding-right: 6px;
                height: 15px;
                line-height: 15px;
                background: rgba(255, 152, 108, 1);
                box-shadow: 0px 1px 1px 0px rgba(255, 91, 118, 0.42);
                border-radius: 7px;
                font-size: 10px;
                font-family: PingFangSC-Medium;
                font-weight: 500;
                color: rgba(255, 255, 255, 1);
                position: relative;
                &::before {
                  content: "";
                  width: 18px;
                  height: 18px;
                  line-height: 18px;
                  text-align: center;
                  border-radius: 50%;
                  display: block;
                  background-image: url("https://h5.ameimeika.com/mp_images/mp_2.4/search/vvvvv@2x.png");
                  background-repeat: no-repeat;
                  background-size: cover;
                  box-shadow: 0px 1px 2px 0px rgba(255, 98, 117, 0.61);
                  position: absolute;
                  left: 0;
                  top: 50%;
                  transform: translate(-50%, -50%);
                  font-size: 12px;
                  font-weight: 500;
                  color: rgba(255, 255, 255, 1);
                }
              }
            }
            .hospic {
              width: 54px;
              height: 54px;
              margin: 0 auto 13px;
              .hosimg {
                border-radius: 50%;
                width: 100%;
                height: 100%;
              }
            }
            .hosname {
              text-align: center;
              font-size: 14px;
              font-family: PingFangSC-Regular;
              font-weight: 400;
              color: #333333;
              line-height: 20px;
              white-space: nowrap;
              overflow: hidden;
              text-overflow: ellipsis;
            }
            .hosaddress {
              text-align: center;
              margin-top: 3px;
              overflow: hidden;
              white-space: nowrap;
              text-overflow: ellipsis;
              .dwimg {
                display: inline-block;
                width: 11px;
                height: 12px;
                line-height: 12px;
                margin-right: 2px;
                vertical-align: -2px;
              }
              .dzmsg {
                display: inline-block;
                font-size: 11px;
                font-family: PingFangSC-Light;
                font-weight: 300;
                color: #666666;
                line-height: 17px;
              }
            }
            .hosscore {
              margin-top: 9px;
              overflow: hidden;
              .lf {
                float: left;
                width: 40%;
                overflow: hidden;
                white-space: nowrap;
                text-overflow: ellipsis;
                .star {
                  display: inline-block;
                  width: 12px;
                  height: 12px;
                  margin-right: 2px;
                }
                .score {
                  display: inline-block;
                  font-size: 11px;
                  font-family: PingFangSC-Regular;
                  font-weight: 400;
                  color: #ff9800;
                  line-height: 16px;
                }
              }
              .rt {
                text-align: right;
                width: 50%;
                float: right;
                font-size: 11px;
                font-family: PingFangSC-Regular;
                font-weight: 400;
                color: #ff9800;
                line-height: 16px;
                overflow: hidden;
                white-space: nowrap;
                text-overflow: ellipsis;
              }
            }
          }
        }
        .daodi {
          text-align: center;
          font-size: 12px;
          font-family: PingFangSC-Regular;
          font-weight: 400;
          color: #999990;
          line-height: 20px;
          padding: 15px 0 20px;
          background-color: rgba(243, 244, 246, 1);
        }
      }
      // 没有找到想要的内容
      .empty {
        width: 154px;
        margin: 0 auto;
        padding: 30% 0;
        box-sizing: border-box;
        .nothing {
          width: 128px;
          height: 114px;
          margin: 0 auto;
          display: block;
        }
        .text {
          width: 100%;
          font-size: 14px;
          font-weight: 400;
          margin-top: 13px;
          color: rgba(153, 153, 153, 1);
          text-align: center;
        }
      }
    }
  }
}
</style>



